package com.qf.lw.service.impl;

import com.github.pagehelper.PageHelper;
import com.qf.lw.entity.AdminEntity;
import com.qf.lw.mapper.AdminMapper;
import com.qf.lw.pojo.AdminPojo;
import com.qf.lw.service.IAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IAdminServiceImpl implements IAdminService {
    @Autowired
    private AdminMapper adminMapper;


    //查询用户的所有信息
    @Override
    public List<AdminPojo> qureyAdminList(AdminEntity adminEntity) {
        PageHelper.startPage(adminEntity.getPageNum(),adminEntity.getPageSize());
        return adminMapper.qureyAdminList(adminEntity);
    }
    //根据用户的用户名和密码，级联查询用户的角色和权限
    ////管理员登陆
    @Override
    public AdminPojo login(AdminEntity adminEntity) {
        return adminMapper.loginQueryAuth(adminEntity);
    }
    //跟据用户的id去查询用户所有的角色和权限
    @Override
    public AdminPojo queryAuthById(String aid) {
        return adminMapper.queryAuthById(aid);
    }

    @Override
    public boolean delAdmins(String[] ids) {
        return adminMapper.delAdmins(ids);
    }

    @Override
    public boolean adminAdd(AdminEntity adminEntity) {
        adminMapper.adminAdd(adminEntity);

        // int i = 1/0; ? 请问用户是否能成功插入到数据库?

        //2: 给用户绑定角色
        boolean bl = adminMapper.bindRoles(adminEntity.getAid() , adminEntity.getRoleids());

        return bl;
    }

    @Override
    public boolean updateAdmin(AdminEntity adminEntity) {
        adminMapper.updateAdmin(adminEntity);
        adminMapper.deteRA(adminEntity.getAid());
        boolean bl = adminMapper.bindRoles(adminEntity.getAid() , adminEntity.getRoleids());
        return bl;
    }
}
